package com.zy.vod.sdk;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.zy.vod.util.AliyunVodSDKUtil;
/*获取播放凭证*/
public class AliyunVodSDKPlayAuth {

    //账号AccessKey信息请填写(必选)
    private static String access_key_id = "LTAI4FeAFe3n8r87buAjKCLE";
    //账号AccessKey信息请填写(必选)
    private static String access_key_secret = "vP2g6zLy0mEtLSGFfDaFametAEJ0N3";

    /*获取播放凭证函数*/
    public static GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client) throws Exception {
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId("39940d43e2c74826b178383e0d832d37");
        return client.getAcsResponse(request);
    }
    /*以下为调用示例*/
    public static void main(String[] argv) throws  Exception{

        DefaultAcsClient client = AliyunVodSDKUtil.initVodClient(access_key_id, access_key_secret);

        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId("视频Id");
        try {
            response = getVideoPlayAuth(client);
            //播放凭证
            System.out.print("PlayAuth = " + response.getPlayAuth() + "\n");
            //VideoMeta信息
            System.out.print("VideoMeta.Title = " + response.getVideoMeta().getTitle() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
        System.out.print("RequestId = " + response.getRequestId() + "\n");
    }

}
